﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace amuudp.package
{
    public class MessagePackage
    {
        public string Message { get; private set; }

        public MessagePackage(Package package)
        {
            if (!package.Complete)
            {
                throw new Exception("数据包接收不完整");
            }

            if (package.Type != PackageType.Message)
            {
                throw new Exception("数据包不是字符串类型");
            }

            this.Message = Encoding.UTF8.GetString(UdpCommon.ByteCopy(package.Bytes, 16, package.Bytes.Length - 16));
        }
    }

}
